package me.fangx.zhihu.presenter;

import android.content.Context;

import java.util.List;

import me.fangx.zhihu.modle.bean.CookBean;
import me.fangx.zhihu.modle.dao.DBManager;
import me.fangx.zhihu.view.CookListView;

public class CookPresenter extends BasePresenter<CookListView> {

    public static final int LIMIT = 10;

    public CookPresenter(Context context) {

    }

    @Override
    public void attachView(CookListView mvpView) {
        super.attachView(mvpView);
    }

    @Override
    public void detachView() {
        super.detachView();
    }


    public void loadList(int type, final int page) {
        checkViewAttached();
        int offset = (page - 1) * LIMIT;
        List<CookBean> cookList = new DBManager().getCookList(type, offset, LIMIT);
//        List<CookBean> cookList = new ArrayList<>();
//        switch (type){
//            case 0:
//                cookList.add(new CookBean(1, 1, 0, 0, "宫保鸡丁", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                cookList.add(new CookBean(2, 2, 0, 0, "小炒肉", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                break;
//            case 1:
//                cookList.add(new CookBean(11, 11, 1, 0, "宫保鸡丁", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                cookList.add(new CookBean(12, 12, 1, 0, "小炒肉", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                break;
//            case 2:
//                cookList.add(new CookBean(21, 21, 2, 0, "宫保鸡丁", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                cookList.add(new CookBean(22, 22, 2, 0, "小炒肉", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                break;
//            case 3:
//                cookList.add(new CookBean(32, 32, 3, 0, "宫保鸡丁", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                cookList.add(new CookBean(33, 33, 3, 0, "小炒肉", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//                break;
//        }

        if (page == 1) {
            getMvpView().refresh(cookList);
        } else {
            getMvpView().loadMore(cookList);
        }

    }

    public void loadCollectList(final int page) {
        checkViewAttached();
        int offset = (page - 1) * LIMIT;
        List<CookBean> cookList = new DBManager().getCollectList(offset, LIMIT);
//        List<CookBean> cookList = new ArrayList<>();
//        cookList.add(new CookBean(1, 1, 0, 0, "宫保鸡丁", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));
//        cookList.add(new CookBean(2, 2, 0, 0, "小炒肉", "黄瓜，鸡肉，花生米，辣椒", "1，加入油盐花生米辣椒爆炒\n2，加入鸡肉中火满炒3分钟\n3，加入黄瓜丁小火慢炒1分钟"));

        if (page == 1) {
            getMvpView().refresh(cookList);
        } else {
            getMvpView().loadMore(cookList);
        }

    }

}